from flask import Blueprint, request, jsonify
from flaskAdminApp.controller.sysUserController import AdminController
from flaskAdminApp.abnormal.errorClass import Success
import json
from flaskAdminApp.token_auth import auth

admin = Blueprint('admin', __name__)


@admin.route('/index')
# @auth.login_required()
def index():
    data = dict(
        a=1,
        b=2
    )
    raise Success(data=data)


@admin.route('/adminLogin', methods=["post"])
def adminLogin():
    phonenumber = request.values.get('phone')
    password = request.values.get('password')

    d = AdminController.Login(phonenumber=phonenumber, password=password)
    return d


@admin.route('/reg', methods=['POST'])
def reg():
    user_name = request.values.get('user_name')
    nick_name = request.values.get('nick_name')
    email = request.values.get('email')
    phonenumber = request.values.get('phonenumber')
    password = request.values.get('password')
    d = AdminController.addUsers(user_name=user_name, nick_name=nick_name, email=email, phonenumber=phonenumber,
                                 password=password)

    return d


@admin.route('/getUserInfo')
def getUserInfo():
    token = request.headers['Authorization']

    return AdminController.tokenGetUserInfo(token=token)
